home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Devices / SCSI Simple Sample / Src / SCSI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  33.1 KB  |  873 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3.     File:        SCSI.h    
  4.  
  5.     Contains:    
  6.         This file contains constants and data structures that are used by
  7.         drivers to interface with both the old and new SCSI Managers.
  8.                         
  9.     Written by:    
  10.         Paul Wolf, Clinton Bauder, Henry Kannapell
  11.  
  12.     Copyright:    © 1986-1994 by Apple Computer, Inc., all rights reserved.
  13.  
  14.     Change History (most recent first):
  15.  
  16.        <SM3>     2/11/94    pdw        Rolled in all of the SCSI Manager 4.3 stuff from the old ACAM.h
  17.                                     file.
  18. ************************************************************/
  19.  
  20.  
  21. #ifndef __SCSI__
  22. #define __SCSI__
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27.  
  28. #ifndef __TRAPS__
  29. #include <Traps.h>
  30. #endif
  31.  
  32.  
  33. /*——————————————————————— Old SCSI Manager Interface ———————————————————————*/
  34.  
  35. /* TIB opcodes */
  36.  
  37. enum {
  38.  scInc    = 1,
  39.  scNoInc= 2,
  40.  scAdd    = 3,
  41.  scMove    = 4,
  42.  scLoop    = 5,
  43.  scNop    = 6,
  44.  scStop    = 7,
  45.  scComp    = 8
  46. };
  47.  
  48.  
  49. /* SCSI Manager errors */
  50.  
  51. enum {
  52.  scCommErr        = 2,            /* communications error, operation timeout */
  53.  scArbNBErr        = 3,            /* arbitration timeout waiting for not BSY */
  54.  scBadParmsErr    = 4,            /* bad parameter or TIB opcode */
  55.  scPhaseErr        = 5,            /* SCSI bus not in correct phase for attempted operation */
  56.  scCompareErr    = 6,            /* data compare error */
  57.  scMgrBusyErr    = 7,            /* SCSI Manager busy  */
  58.  scSequenceErr    = 8,            /* attempted operation is out of sequence */
  59.  scBusTOErr        = 9,            /* CPU bus timeout */
  60.  scComplPhaseErr= 10            /* SCSI bus wasn't in Status phase */
  61. };
  62.  
  63.  
  64. /* Signatures */
  65.  
  66. enum {
  67.     sbSIGWord    = 0x4552,        /* signature word for Block 0 ('ER') */
  68.     sbMac        = 1,            /* system type for Mac */
  69.     pMapSIG        = 0x504D,        /* partition map signature ('PM') */
  70.     pdSigWord    = 0x5453
  71. };
  72.  
  73. #define oldPMSigWord pdSigWord    
  74. #define newPMSigWord pMapSIG
  75.  
  76.  
  77. /* Driver Descriptor Map */
  78.  
  79. struct Block0 {
  80.  unsigned short sbSig;                /* unique value for SCSI block 0 */
  81.  unsigned short sbBlkSize;            /* block size of device */
  82.  unsigned long sbBlkCount;            /* number of blocks on device */
  83.  unsigned short sbDevType;            /* device type */
  84.  unsigned short sbDevId;            /* device id */
  85.  unsigned long sbData;                /* not used */
  86.  unsigned short sbDrvrCount;        /* driver descriptor count */
  87.  unsigned long ddBlock;                /* 1st driver's starting block */
  88.  unsigned short ddSize;                /* size of 1st driver (512-byte blks) */
  89.  unsigned short ddType;                /* system type (1 for Mac+) */
  90.  unsigned short ddPad[243];            /* ARRAY[0..242] OF INTEGER; not used */
  91. };
  92.  
  93. typedef struct Block0 Block0;
  94.  
  95.  
  96. /* Partition Map Entry */
  97.  
  98. struct Partition {
  99.  unsigned short pmSig;                /* unique value for map entry blk */
  100.  unsigned short pmSigPad;            /* currently unused */
  101.  unsigned long pmMapBlkCnt;            /* # of blks in partition map */
  102.  unsigned long pmPyPartStart;        /* physical start blk of partition */
  103.  unsigned long pmPartBlkCnt;        /* # of blks in this partition */
  104.  unsigned char pmPartName[32];        /* ASCII partition name */
  105.  unsigned char pmParType[32];        /* ASCII partition type */
  106.  unsigned long pmLgDataStart;        /* log. # of partition's 1st data blk */
  107.  unsigned long pmDataCnt;            /* # of blks in partition's data area */
  108.  unsigned long pmPartStatus;        /* bit field for partition status */
  109.  unsigned long pmLgBootStart;        /* log. blk of partition's boot code */
  110.  unsigned long pmBootSize;            /* number of bytes in boot code */
  111.  unsigned long pmBootAddr;            /* memory load address of boot code */
  112.  unsigned long pmBootAddr2;            /* currently unused */
  113.  unsigned long pmBootEntry;            /* entry point of boot code */
  114.  unsigned long pmBootEntry2;        /* currently unused */
  115.  unsigned long pmBootCksum;            /* checksum of boot code */
  116.  unsigned char pmProcessor[16];        /* ASCII for the processor type */
  117.  unsigned short pmPad[188];            /* 512 bytes long currently unused */
  118. };
  119.  
  120. typedef struct Partition Partition;
  121.  
  122.  
  123. /* TIB instruction */
  124.  
  125. struct SCSIInstr {
  126.  unsigned short scOpcode;
  127.  unsigned long scParam1;
  128.  unsigned long scParam2;
  129. };
  130.  
  131. typedef struct SCSIInstr SCSIInstr;
  132.  
  133.  
  134. #ifdef __cplusplus
  135. extern "C" {
  136. #endif
  137. pascal OSErr SCSIReset(void)
  138.  = {0x4267,0xA815}; 
  139. pascal OSErr SCSIGet(void)
  140.  = {0x3F3C,0x0001,0xA815}; 
  141. pascal OSErr SCSISelect(short targetID)
  142.  = {0x3F3C,0x0002,0xA815}; 
  143. pascal OSErr SCSICmd(Ptr buffer,short count)
  144.  = {0x3F3C,0x0003,0xA815}; 
  145. pascal OSErr SCSIRead(Ptr tibPtr)
  146.  = {0x3F3C,0x0005,0xA815}; 
  147. pascal OSErr SCSIRBlind(Ptr tibPtr)
  148.  = {0x3F3C,0x0008,0xA815}; 
  149. pascal OSErr SCSIWrite(Ptr tibPtr)
  150.  = {0x3F3C,0x0006,0xA815}; 
  151. pascal OSErr SCSIWBlind(Ptr tibPtr)
  152.  = {0x3F3C,0x0009,0xA815}; 
  153. pascal OSErr SCSIComplete(short *stat,short *message,unsigned long wait)
  154.  = {0x3F3C,0x0004,0xA815}; 
  155. pascal short SCSIStat(void)
  156.  = {0x3F3C,0x000A,0xA815}; 
  157. pascal OSErr SCSISelAtn(short targetID)
  158.  = {0x3F3C,0x000B,0xA815}; 
  159. pascal OSErr SCSIMsgIn(short *message)
  160.  = {0x3F3C,0x000C,0xA815}; 
  161. pascal OSErr SCSIMsgOut(short message)
  162.  = {0x3F3C,0x000D,0xA815}; 
  163. #ifdef __cplusplus
  164. }
  165. #endif
  166.  
  167.  
  168.  
  169. /*——————————————————————— New SCSI Manager Interface ———————————————————————*/
  170.  
  171.  
  172. enum {
  173.     scsiVERSION    = 43
  174. };
  175.  
  176. /********************************************************************/
  177. // Defines for the SCSIMgr function codes
  178. /********************************************************************/
  179.  
  180. enum
  181. {
  182. //------------ Common Functions ------------
  183.  
  184.     SCSINop                        = 0x00,      // Execute nothing
  185.     SCSIExecIO                      = 0x01,      // Execute the specified IO
  186.     SCSIBusInquiry              = 0x03,     // Get parameters for entire path of HBAs
  187.     SCSIReleaseQ                = 0x04,        // Release the frozen SIM queue for particular LUN 
  188.     SCSISetAsyncCallback        = 0x05,        // Set async event call back 
  189.  
  190. //------------ Control Functions         ------------
  191.  
  192.     SCSIAbortCommand            = 0x10,        // Abort the selected Control Block 
  193.     SCSIResetBus                = 0x11,        // Reset the SCSI bus 
  194.     SCSIResetDevice                = 0x12,        // Reset the SCSI device 
  195.     SCSITerminateIO                = 0x13,        // Terminate any pending IO 
  196.  
  197. //------------ Target Mode Functions      ------------
  198.  
  199.     SCSIEnableLUN                = 0x30,        // Enable LUN, Target mode support
  200.     SCSITargetIO                = 0x31,        // Execute the target IO request
  201.  
  202. //------------ Apple Added                 ------------
  203.  
  204.     SCSIGetVirtualIDInfo        = 0x80,        // Find out which bus old ID is on                            
  205.     SCSIGenerateInterleaveID    = 0x81,        // Generate a new interleave factor
  206.     SCSILoadDriver                = 0x82,        // Load a driver for a device ident
  207.     SCSIOldCall                    = 0x84,        // XPT->SIM private call for old-API
  208.     SCSICreateRefNumXref        = 0x85,        // Register a DeviceIdent to drvr RefNum xref
  209.     SCSILookupRefNumXref        = 0x86,        // Get DeviceIdent to drvr RefNum xref
  210.     SCSIRemoveRefNumXref        = 0x87,        // Remove a DeviceIdent to drvr RefNum xref
  211.     SCSIRegisterWithNewXPT        = 0x88        // XPT has changed - SIM needs to re-register itself
  212.  
  213. //------------ 3rd-party Vendor Unique     ------------                            
  214.  
  215. // 0xC0 thru 0xFF
  216. };
  217.  
  218.  
  219. /********************************************************************/
  220. /*    SCSI Parameter Block Elements                                    */
  221. /********************************************************************/
  222.  
  223. typedef pascal void (*CallbackProc) (void * ioPtr);
  224.  
  225.  
  226. //————— Allocation length defines for some of the fields —————
  227.  
  228. enum {
  229.     handshakeDataLength        = 8,        // Handshake data length
  230.     maxCDBLength            = 16,        // Space for the CDB bytes/pointer
  231.     vendorIDLength            = 16        // ASCII string len for Vendor ID 
  232. };
  233.  
  234. //————— Define DeviceIdent structure —————
  235.  
  236. typedef struct DeviceIdent 
  237. {
  238.     unsigned char        diReserved;            // reserved
  239.     unsigned char        bus;                // SCSI - Bus #
  240.     unsigned char        targetID;            // SCSI - Target SCSI ID
  241.     unsigned char        LUN;                // SCSI - LUN 
  242. } DeviceIdent;
  243.  
  244.  
  245. //————— Command Descriptor Block structure —————
  246.  
  247. typedef union CDB
  248. {
  249.     unsigned char *        cdbPtr;                        // ptr to the CDB bytes to send, or…
  250.     unsigned char        cdbBytes[ maxCDBLength ];    // actual CDB to send
  251. } CDB, *CDBPtr;
  252.  
  253.  
  254. //————— Scatter/gather list element —————
  255.  
  256. typedef    struct SGRecord 
  257. {
  258.     Ptr        SGAddr;
  259.     unsigned long    SGCount;
  260. } SGRecord;
  261.  
  262.  
  263.  
  264.  
  265. /********************************************************************/
  266. /*    SCSI Parameter Block Definitions                                */
  267. /********************************************************************/
  268.  
  269. //====== Common SCSI PB header fields macro ======
  270.  
  271. #define SCSIPBHdr \
  272.     struct SCSIHdr * qLink;                /* (internal) Q link to next PB         */ \
  273.     short            scsiReserved1;        /* ->     reserved for input                */ \
  274.     unsigned short            scsiPBLength;        /* -> Length of the entire PB            */ \
  275.     unsigned char            scsiFunctionCode;    /* -> function selector                 */ \
  276.     unsigned char            scsiReserved2;        /* <-     reserved for output                */ \
  277.     OSErr            scsiResult;            /* <- Returned result                     */ \
  278.     DeviceIdent        scsiDevice;            /* -> Device Identifier (bus+target+lun)*/ \
  279.     CallbackProc    scsiCompletion;        /* -> Callback on completion function      */ \
  280.     unsigned long            scsiFlags;            /* -> assorted flags                    */ \
  281.     unsigned char *            scsiDriverStorage;    /* <> Ptr for driver private use        */ \
  282.     Ptr                scsiXPTprivate;        /* private field for use in XPT            */ \
  283.     long            scsiReserved3;        /* reserved                                */
  284. // end of SCSIPBHdr
  285.  
  286.  
  287. //——————————————  SCSI PB Header  ——————————————
  288.  
  289. typedef struct SCSIHdr
  290. {
  291.     SCSIPBHdr
  292. } SCSIHdr;
  293.  
  294. typedef struct SCSI_PB
  295. {
  296.     SCSIPBHdr
  297. } SCSI_PB;
  298.  
  299.  
  300. //——————————————  SCSI I/O Request PB  ——————————————
  301.                                                                 
  302. #define SCSI_IO_Macro \
  303.     SCSIPBHdr                            /* Header information fields                        */ \
  304.     unsigned short        scsiResultFlags;        /* <- Flags which modify the scsiResult field        */ \
  305.     unsigned short        scsiInterleaveID;        /* -> used to designate interleavability of request    */ \
  306.     unsigned char *        scsiDataPtr;            /* -> Pointer to the data buffer or the S/G list      */ \
  307.     unsigned long        scsiDataLength;            /* -> Data transfer length                            */ \
  308.     unsigned char *        scsiSensePtr;            /* -> Ptr to autosense data buffer                  */ \
  309.     unsigned char        scsiSenseLength;        /* -> size of the autosense buffer                     */ \
  310.     unsigned char        scsiCDBLength;            /* -> Number of bytes for the CDB                      */ \
  311.     unsigned short        scsiSGListCount;        /* -> num of scatter gather list entries              */ \
  312.     unsigned long        scsiReserved4;            /* <-     reserved for output                            */ \
  313.     unsigned char        scsiSCSIstatus;            /* <- Returned scsi device status                      */ \
  314.     char        scsiSenseResidual;        /* <- Autosense residual length                      */ \
  315.     unsigned short        scsiReserved5;            /* <-     reserved for output                             */ \
  316.     long        scsiDataResidual;        /* <- Returned Transfer residual length              */ \
  317.     CDB            scsiCDB;                /* -> Actual CDB or pointer to CDB                  */ \
  318.     long        scsiTimeout;            /* -> Timeout value (Time Mgr format) (CAM timeout) */ \
  319.     unsigned char *        scsiMessagePtr;            /* -> Pointer to the message buffer -target md only    */ \
  320.     unsigned short        scsiMessageLen;            /* -> Num of bytes in the msg bfr    -target md only    */ \
  321.     unsigned short        scsiIOFlags;            /* -> additional I/O flags                               */ \
  322.     unsigned char        scsiTagAction;            /* -> What to do for tag queuing                       */ \
  323.     unsigned char        scsiReserved6;            /* ->     reserved for input                             */ \
  324.     unsigned short        scsiReserved7;            /* ->     reserved for input                             */ \
  325.     unsigned short        scsiSelectTimeout;        /* -> Select timeout value                             */ \
  326.     unsigned char        scsiDataType;            /* -> Data description type (i.e. buffer, TIB, S/G)    */ \
  327.     unsigned char        scsiTransferType;        /* -> Transfer type (i.e. Blind vs Polled)             */ \
  328.     unsigned long        scsiReserved8;            /* ->     reserved for input                             */ \
  329.     unsigned long        scsiReserved9;            /* ->     reserved for input                             */ \
  330.     unsigned short        scsiHandshake[handshakeDataLength];    /* -> handshaking points (null term'd)    */ \
  331.     unsigned long        scsiReserved10;            /* ->     reserved for input                             */ \
  332.     unsigned long        scsiReserved11;            /* ->   reserved for input                            */ \
  333.     struct SCSI_IO *scsiCommandLink;    /* -> Ptr to the next PB in linked cmd chain         */ \
  334.                                         \
  335.     unsigned char        scsiSIMpublics[8];        /* ->     reserved for input to 3rd-party SIMs        */ \
  336.     unsigned char        scsiAppleReserved6[8];    /* ->    reserved for input                              */ \
  337.                                         \
  338. /* XPT layer privates (for old-API emulation) */ \
  339.                                         \
  340.     unsigned short        scsiCurrentPhase;        /* <- phase upon completing old call                  */ \
  341.     short        scsiSelector;            /* -> selector specified in old calls                  */ \
  342.     OSErr        scsiOldCallResult;        /* <- result of old call                              */ \
  343.     unsigned char        scsiSCSImessage;        /* <- Returned scsi device message (for SCSIComplete)*/ \
  344.     unsigned char        XPTprivateFlags;        /* <> various flags                                   */ \
  345.     unsigned char        XPTextras[12];            /*                                                    */
  346.  
  347. // end of SCSI_IO_Macro
  348.  
  349.  
  350. typedef struct SCSI_IO
  351. {
  352.     SCSI_IO_Macro
  353. } SCSI_IO;
  354.  
  355. #define SCSIExecIOPB    SCSI_IO
  356.     
  357.  
  358.     
  359.  
  360. //——————————————  Bus inquiry PB ——————————————
  361. typedef struct SCSIBusInquiryPB
  362. {
  363.     SCSIPBHdr                            // Header information fields
  364.     unsigned short        scsiEngineCount;        // <- Number of engines on HBA
  365.     unsigned short        scsiMaxTransferType;    // <- Number of transfer types for this HBA
  366.  
  367.     unsigned long        scsiDataTypes;            // <- which data types are supported by this SIM
  368.  
  369.     unsigned short        scsiIOpbSize;            // <- Size of SCSI_IO PB for this SIM/HBA
  370.     unsigned short        scsiMaxIOpbSize;        // <- Size of max SCSI_IO PB for all SIM/HBAs
  371.     
  372.     unsigned long        scsiFeatureFlags;        // <- Supported features flags field
  373.  
  374.     unsigned char        scsiVersionNumber;        // <- Version number for the SIM/HBA
  375.     unsigned char        scsiHBAInquiry;            // <- Mimic of INQ byte 7 for the HBA
  376.     unsigned char        scsiTargetModeFlags;    // <- Flags for target mode support
  377.     unsigned char        scsiScanFlags;            // <- Scan related feature flags
  378.  
  379.     unsigned long        scsiSIMPrivatesPtr;        // <- Ptr to SIM private data area
  380.     unsigned long        scsiSIMPrivatesSize;    // <- Size of SIM private data area
  381.     unsigned long        scsiAsyncFlags;            // <- Event cap. for Async Callback
  382.  
  383.     unsigned char        scsiHiBusID;            // <- Highest path ID in the subsystem 
  384.     unsigned char        scsiInitiatorID;        // <- ID of the HBA on the SCSI bus
  385.     unsigned short        scsiBIReserved0;
  386.  
  387.     unsigned long        scsiBIReserved1;        // <- 
  388.     unsigned long        scsiFlagsSupported;        // <- which scsiFlags are supported
  389.  
  390.     unsigned short        scsiIOFlagsSupported;    // <- which scsiIOFlags are supported
  391.     unsigned short         scsiWeirdStuff;            // <- 
  392.     unsigned short        scsiMaxTarget;            // <- maximum Target number supported
  393.     unsigned short        scsiMaxLUN;                // <- maximum Logical Unit number supported
  394.  
  395.     char        scsiSIMVendor[ vendorIDLength ];        // <- Vendor ID of SIM (or XPT if bus<FF)
  396.     char        scsiHBAVendor[ vendorIDLength ];        // <- Vendor ID of the HBA
  397.     char        scsiControllerFamily[ vendorIDLength ];    // <- Family of SCSI Controller
  398.     char        scsiControllerType[ vendorIDLength ];    // <- Specific Model of SCSI Controller used
  399.  
  400.     char        scsiXPTversion[4];        // <- version number of XPT
  401.     char        scsiSIMversion[4];        // <- version number of SIM
  402.     char        scsiHBAversion[4];        // <- version number of HBA
  403.     
  404.     unsigned char        scsiHBAslotType;        // <- type of "slot" that this HBA is in
  405.     unsigned char        scsiHBAslotNumber;        // <- slot number of this HBA
  406.     unsigned short        scsiSIMsRsrcID;            // <- resource ID of this SIM
  407.     
  408.     unsigned short         scsiBIReserved3;        // <- 
  409.     unsigned short        scsiAdditionalLength;    // <- additional BusInquiry PB len
  410. } SCSIBusInquiryPB;
  411.  
  412.  
  413. //——————————————  Abort SIM Request PB  ——————————————
  414. typedef struct SCSIAbortCommandPB
  415. {
  416.     SCSIPBHdr                            // Header information fields
  417.     SCSI_IO *     scsiIOptr;                // Pointer to the PB to abort
  418. } SCSIAbortCommandPB;                    // <SM3>
  419.  
  420.  
  421. //——————————————  Terminate I/O Process Request PB  ——————————————
  422. typedef struct SCSITerminateIOPB
  423. {
  424.     SCSIPBHdr                            // Header information fields
  425.     SCSI_IO *     scsiIOptr;                // Pointer to the PB to terminate
  426. } SCSITerminateIOPB;                    // <SM3>
  427.  
  428.  
  429. //——————————————  Reset SCSI Bus PB ——————————————
  430. typedef struct SCSIResetBusPB
  431. {
  432.     SCSIPBHdr                            // Header information fields
  433. } SCSIResetBusPB;                        // <SM3>
  434.  
  435.  
  436. //——————————————  Reset SCSI Device PB  ——————————————
  437. typedef struct SCSIResetDevicePB
  438. {
  439.     SCSIPBHdr                            // Header information fields
  440. } SCSIResetDevicePB;                    // <SM3>
  441.  
  442.  
  443. //——————————————  Release SIM Queue PB  ——————————————
  444. typedef struct SCSIReleaseQPB
  445. {
  446.     SCSIPBHdr                            // Header information fields
  447. } SCSIReleaseQPB;
  448.  
  449.  
  450. //——————————————  Set Async Event Callback PB  ——————————————
  451. typedef struct SCSISetAsyncCallbackPB
  452. {
  453.     SCSIPBHdr                            // Header information fields
  454.     unsigned long        scsiEventFlags;            // -> events to be notified of
  455.     void        (*scsiEventCallback)();    // -> routine to call when event occurs
  456.     unsigned char *        scsiEventInfoPtr;        // -> ptr to buffer for additional info
  457.     unsigned char        scsiEventInfoLen;        // -> length of buffer
  458.     unsigned char        scsiReserved11;            // 
  459.     unsigned short        scsiReserved12;            // 
  460. } SCSISetAsyncCallbackPB;
  461.  
  462.  
  463. //——————————————  SCSI Get Virtual ID Info PB  ——————————————
  464. typedef struct SCSIGetVirtualIDInfoPB
  465. {
  466.     SCSIPBHdr                        // Header information fields 
  467.     unsigned short        scsiOldCallID;        // -> SCSI ID of device in question
  468.     Boolean        scsiExists;            // <- true if device exists
  469. } SCSIGetVirtualIDInfoPB;
  470.  
  471.  
  472. //——————————————  SCSI Generate Interleave ID PB  ——————————————
  473. typedef struct SCSIGenerateInterleaveIDPB
  474. {
  475.     SCSIPBHdr                        // Header information fields 
  476.     unsigned short        scsiInterleaveID;    // <- SCSI ID of device in question
  477.     unsigned short        scsiReserved13;        // 
  478. } SCSIGenerateInterleaveIDPB;
  479.  
  480.  
  481. //——————————————  Create/Lookup/Remove RefNum for Device PB  ——————————————
  482. typedef struct SCSIDriverPB
  483. {
  484.     SCSIPBHdr                            // Header information fields
  485.     short        scsiDriver;                // -> DriverRefNum, For SetDriver
  486.                                         // <- For GetNextDriver
  487.     unsigned short        scsiDriverFlags;        // <> Details of driver/device
  488.     DeviceIdent    scsiNextDevice;            // <- DeviceIdent of the NEXT Item in the list 
  489. } SCSI_Driver_PB;
  490.  
  491.  
  492. //——————————————  Load Driver PB ——————————————
  493. typedef struct SCSILoadDriverPB
  494. {
  495.     SCSIPBHdr                            // Header information fields
  496.     short        scsiLoadedRefNum;        // <- SIM returns refnum of driver
  497.     Boolean        scsiDiskLoadFailed;        // -> if true, indicates call after failure to load
  498. } SCSILoadDriverPB;                        //
  499.  
  500. //======================================================================
  501.  
  502. /******************************************************************************/
  503. // Values for the fields in SCSI PBs
  504. /******************************************************************************/
  505.  
  506. //———————————————————————————————————————————————————————————————————————————————————
  507. // Defines for the scsiTransferType field
  508. //———————————————————————————————————————————————————————————————————————————————————
  509.  
  510. enum {
  511.         scsiTransferBlind = 0,
  512.         scsiTransferPolled
  513. };    
  514.  
  515. //———————————————————————————————————————————————————————————————————————————————————
  516. // Defines for the scsiDataType field
  517. //———————————————————————————————————————————————————————————————————————————————————
  518.  
  519. enum {
  520.         scsiDataBuffer     = 0,        // single contiguous buffer supplied 
  521.         scsiDataTIB     = 1,        // TIB supplied (ptr in scsiDataPtr)
  522.         scsiDataSG         = 2            // scatter/gather list supplied 
  523. };    
  524.  
  525. //———————————————————————————————————————————————————————————————————————————————————
  526. // Defines for the SCSIMgr scsiResult field in the PB header.
  527. //  $E100 thru  E1FF
  528. // -$1EFF thru -1E00
  529. // -#7935 thru -7681 
  530. //———————————————————————————————————————————————————————————————————————————————————
  531.  
  532. #define        scsiErrorBase        -7936                    // = 0xE100 
  533.  
  534. enum {
  535.     scsiRequestInProgress        = 1,                    // 1     = PB request is in progress
  536.  
  537. // Execution failed  00-2F
  538.     scsiRequestAborted            = (scsiErrorBase+0x02),    // -7934 = PB request aborted by the host
  539.     scsiUnableToAbort            = (scsiErrorBase+0x03),    // -7933 = Unable to Abort PB request
  540.     scsiNonZeroStatus            = (scsiErrorBase+0x04),    // -7932 = PB request completed with an err
  541.     scsiUnused05                = (scsiErrorBase+0x05),    // -7931 = 
  542.     scsiUnused06                = (scsiErrorBase+0x06),    // -7930 = 
  543.     scsiUnused07                = (scsiErrorBase+0x07),    // -7929 = 
  544.     scsiUnused08                = (scsiErrorBase+0x08),    // -7928 = 
  545.     scsiUnableToTerminate        = (scsiErrorBase+0x09),    // -7927 = Unable to Terminate I/O PB req
  546.     scsiSelectTimeout            = (scsiErrorBase+0x0A),    // -7926 = Target selection timeout
  547.     scsiCommandTimeout            = (scsiErrorBase+0x0B),    // -7925 = Command timeout 
  548.     scsiIdentifyMessageRejected    = (scsiErrorBase+0x0C),    // -7924 = 
  549.     scsiMessageRejectReceived    = (scsiErrorBase+0x0D),    // -7923 = Message reject received 
  550.     scsiSCSIBusReset            = (scsiErrorBase+0x0E),    // -7922 = SCSI bus reset sent/received
  551.     scsiParityError                = (scsiErrorBase+0x0F),    // -7921 = Uncorrectable parity error occured
  552.     scsiAutosenseFailed            = (scsiErrorBase+0x10),    // -7920 = Autosense: Request sense cmd fail
  553.     scsiUnused11                = (scsiErrorBase+0x11),    // -7919 = 
  554.     scsiDataRunError            = (scsiErrorBase+0x12),    // -7918 = Data overrun/underrun error 
  555.     scsiUnexpectedBusFree        = (scsiErrorBase+0x13),    // -7917 = Unexpected BUS free 
  556.     scsiSequenceFailed            = (scsiErrorBase+0x14),    // -7916 = Target bus phase sequence failure
  557.     scsiWrongDirection            = (scsiErrorBase+0x15),    // -7915 = Data phase was in unexpected direction
  558.     scsiUnused16                = (scsiErrorBase+0x16),    // -7914 = 
  559.     scsiBDRsent                    = (scsiErrorBase+0x17),    // -7913 = A SCSI BDR msg was sent to target
  560.     scsiTerminated                = (scsiErrorBase+0x18),    // -7912 = PB request terminated by the host
  561.     scsiNoNexus                    = (scsiErrorBase+0x19),    // -7911 = Nexus is not established
  562.     scsiCDBReceived                = (scsiErrorBase+0x1A),    // -7910 = The SCSI CDB has been received
  563.  
  564. // Couldn't begin execution  30-3F
  565.     scsiTooManyBuses            = (scsiErrorBase+0x30),    // -7888 = Register failed because we're full
  566.     scsiBusy                    = (scsiErrorBase+0x31),    // -7887 = SCSI subsystem is busy
  567.     scsiProvideFail                = (scsiErrorBase+0x32),    // -7886 = Unable to provide requ. capability
  568.     scsiDeviceNotThere            = (scsiErrorBase+0x33),    // -7885 = SCSI device not installed/there 
  569.     scsiNoHBA                    = (scsiErrorBase+0x34),    // -7884 = No HBA detected Error
  570.     scsiDeviceConflict            = (scsiErrorBase+0x35),    // -7883 = sorry, max 1 refNum per DeviceIdent
  571.     scsiNoSuchXref                = (scsiErrorBase+0x36),    // -7882 = no such RefNum xref
  572.     scsiQLinkInvalid            = (scsiErrorBase+0x37),    // -7881 = pre-linked PBs not supported (QLink field nonzero)
  573.  
  574. // Parameter errors  40-7F
  575.     scsiPBLengthError            = (scsiErrorBase+0x40),    // -7872 = length (scsiPBLength) is insuf'ct/invalid
  576.     scsiFunctionNotAvailable    = (scsiErrorBase+0x41),    // -7871 = The requ. func is not available 
  577.     scsiRequestInvalid            = (scsiErrorBase+0x42),    // -7970 = PB request is invalid
  578.     scsiBusInvalid                = (scsiErrorBase+0x43),    // -7969 = Bus ID supplied is invalid 
  579.     scsiTIDInvalid                = (scsiErrorBase+0x44),    // -7868 = Target ID supplied is invalid
  580.     scsiLUNInvalid                = (scsiErrorBase+0x45),    // -7867 = LUN supplied is invalid 
  581.     scsiIIDInvalid                = (scsiErrorBase+0x46),    // -7866 = The initiator ID is invalid 
  582.     scsiDataTypeInvalid            = (scsiErrorBase+0x47),    // -7865 = scsiDataType requested is not supported
  583.     scsiTransferTypeInvalid        = (scsiErrorBase+0x48),    // -7864 = scsiTransferType field is too high
  584.     scsiCDBLengthInvalid        = (scsiErrorBase+0x49)    // -7863 = scsiCDBLength field is too big
  585. };
  586.  
  587. #define scsiExecutionErrors        scsiErrorBase
  588. #define scsiNotExecutedErrors    scsiTooManyBuses
  589. #define scsiParameterErrors        scsiPBLengthError
  590.  
  591. //———————————————————————————————————————————————————————————————————————————————————
  592. //  Defines for the scsiResultFlags field
  593. //———————————————————————————————————————————————————————————————————————————————————
  594.  
  595. #define    scsiSIMQFrozen            0x0001    // The SIM queue is frozen w/this err
  596. #define    scsiAutosenseValid        0x0002    // Autosense data valid for target 
  597. #define    scsiBusNotFree            0x0004    // At time of callback, SCSI bus is not free 
  598.  
  599.  
  600. //———————————————————————————————————————————————————————————————————————————————————
  601. // Defines for the scsiFlags field in the PB header for the SCSIExecIO function
  602. //———————————————————————————————————————————————————————————————————————————————————
  603.  
  604. enum
  605. {
  606. // 1st Byte
  607.  
  608.     kbSCSIDisableAutosense        = 29,    // Disable auto sense feature
  609.     kbSCSIFlagReservedA            = 28,    // 
  610.     
  611.     kbSCSIFlagReserved0            = 27,    // 
  612.     kbSCSICDBLinked                = 26,    // The PB contains a linked CDB
  613.     kbSCSIQEnable                = 25,    // Target queue actions are enabled
  614.     kbSCSICDBIsPointer            = 24,    // The CDB field contains a pointer
  615.     
  616. // 2nd Byte
  617.     
  618.     kbSCSIFlagReserved1            = 23,    // 
  619.     kbSCSIInitiateSyncData        = 22,    // Attempt Sync data xfer and SDTR
  620.     kbSCSIDisableSyncData        = 21,    // Disable sync, go to async
  621.     kbSCSISIMQHead                = 20,    // Place PB at the head of SIM Q
  622.     
  623.     kbSCSISIMQFreeze            = 19,    // Return the SIM Q to frozen state
  624.     kbSCSISIMQNoFreeze            = 18,    // Disallow SIM Q freezing
  625.     kbSCSIDoDisconnect            = 17,    // Definitely do disconnect
  626.     kbSCSIDontDisconnect        = 16,    // Definitely don't disconnect
  627.     
  628. // 3rd Byte
  629.     
  630.     kbSCSIDataReadyForDMA        = 15,    // Data buffer(s) are ready for DMA
  631.     kbSCSIFlagReserved3            = 14,    // 
  632.     kbSCSIDataPhysical            = 13,    // SG/Buffer data ptrs are physical
  633.     kbSCSISensePhysical            = 12,    // Autosense buffer ptr is physical
  634.     
  635.     kbSCSIFlagReserved5            = 11,    // 
  636.     kbSCSIFlagReserved6            = 10,    // 
  637.     kbSCSIFlagReserved7            = 9,    // 
  638.     kbSCSIFlagReserved8            = 8,    // 
  639.     
  640. // 4th Byte - Target Mode Flags
  641.     
  642.     kbSCSIDataBufferValid        = 7,    // Data buffer valid
  643.     kbSCSIStatusBufferValid        = 6,    // Status buffer valid 
  644.     kbSCSIMessageBufferValid    = 5,    // Message buffer valid
  645.     kbSCSIFlagReserved9            = 4,    // 
  646.     
  647.     kbSCSITargetPhaseMode        = 3,    // The SIM will run in phase mode
  648.     kbSCSITargetPBAvail            = 2,    // Target PB available 
  649.     kbSCSIDisableAutoDisconnect    = 1,    // Disable autodisconnect
  650.     kbSCSIDisableAutoSaveRestore= 0        // Disable autosave/restore ptrs
  651. };
  652.  
  653.  
  654. // 1st Byte
  655.  
  656. #define    scsiDirectionMask        0xC0000000    // Data direction mask
  657.  
  658. #define scsiDirectionNone        0xC0000000    // Data direction (11: no data)
  659. #define    scsiDirectionReserved    0x00000000    // Data direction (00: reserved)
  660. #define    scsiDirectionOut        0x80000000    // Data direction (10: DATA OUT)
  661. #define    scsiDirectionIn            0x40000000    // Data direction (01: DATA IN)
  662. #define    scsiDisableAutosense    0x20000000    // Disable auto sense feature
  663. #define    scsiFlagReservedA        0x10000000    // 
  664.  
  665. #define    scsiFlagReserved0        0x08000000    // 
  666. #define    scsiCDBLinked            0x04000000    // The PB contains a linked CDB
  667. #define    scsiQEnable                0x02000000    // Target queue actions are enabled
  668. #define    scsiCDBIsPointer        0x01000000    // The CDB field contains a pointer
  669.  
  670. // 2nd Byte
  671.  
  672. #define    scsiFlagReserved1        0x00800000    // 
  673. #define    scsiInitiateSyncData    0x00400000    // Attempt Sync data xfer and SDTR
  674. #define    scsiDisableSyncData        0x00200000    // Disable sync, go to async
  675. #define    scsiSIMQHead            0x00100000    // Place PB at the head of SIM Q
  676.  
  677. #define    scsiSIMQFreeze            0x00080000    // Return the SIM Q to frozen state
  678. #define    scsiSIMQNoFreeze        0x00040000    // Disallow SIM Q freezing
  679. #define    scsiDoDisconnect        0x00020000    // Definitely do disconnect
  680. #define    scsiDontDisconnect        0x00010000    // Definitely don't disconnect
  681.  
  682. // 3rd Byte
  683.  
  684. #define    scsiDataReadyForDMA        0x00008000    // Data buffer(s) are ready for DMA
  685. #define    scsiFlagReserved3        0x00004000    // 
  686. #define    scsiDataPhysical        0x00002000    // SG/Buffer data ptrs are physical
  687. #define    scsiSensePhysical        0x00001000    // Autosense buffer ptr is physical
  688.  
  689. #define    scsiFlagReserved5        0x00000800    // 
  690. #define    scsiFlagReserved6        0x00000400    // 
  691. #define    scsiFlagReserved7        0x00000200    // 
  692. #define    scsiFlagReserved8        0x00000100    // 
  693.  
  694. // 4th Byte - Target Mode Flags
  695.  
  696. #define    scsiDataBufferValid            0x00000080    // Data buffer valid
  697. #define    scsiStatusBufferValid        0x00000040    // Status buffer valid 
  698. #define    scsiMessageBufferValid        0x00000020    // Message buffer valid
  699. #define    scsiFlagReserved9            0x00000010    // 
  700.  
  701. #define    scsiTargetPhaseMode            0x00000008    // The SIM will run in phase mode
  702. #define    scsiTargetPBAvail            0x00000004    // Target PB available 
  703. #define    scsiDisableAutoDisconnect    0x00000002    // Disable autodisconnect
  704. #define    scsiDisableAutoSaveRestore    0x00000001    // Disable autosave/restore ptrs
  705.  
  706. #define    scsiTargetModeFlagsMask        0x000000FF    // all of the target mode bits
  707.  
  708.  
  709.  
  710. //————————————————————————————————————————
  711. // scsiIOFlags
  712. //————————————————————————————————————————
  713.  
  714. #define    scsiNoParityCheck            0x0002    // disable parity checking 
  715. #define    scsiDisableSelectWAtn        0x0004    // disable select w/Atn 
  716. #define    scsiSavePtrOnDisconnect        0x0008    // do SaveDataPointer upon Disconnect msg
  717. #define    scsiNoBucketIn                0x0010    // don’t bit bucket in during this I/O
  718. #define    scsiNoBucketOut                0x0020    // don’t bit bucket out during this I/O
  719. #define    scsiDisableWide                0x0040    // disable wide transfer negotiation
  720. #define    scsiInitiateWide            0x0080    // initiate wide transfer negotiation
  721. #define    scsiRenegotiateSense        0x0100    // renegotiate sync/wide before issuing autosense
  722.  
  723. #define    scsiIOFlagReserved0080        0x0080    // 
  724. #define    scsiIOFlagReserved8000        0x8000    // 
  725.  
  726.  
  727. //——————————————————————————————————————————————————————————————————————
  728. // Defines for the SIM/HBA queue actions.  These values are used in the
  729. // SCSIExecIOPB, for the queue action field. [These values should match the
  730. // defines from some other include file for the SCSI message phases.  We may
  731. // not need these definitions here. ]
  732.  
  733. enum {
  734.     scsiSimpleQTag            = 0x20,        // Tag for a simple queue
  735.     scsiHeadQTag            = 0x21,        // Tag for head of queue 
  736.     scsiOrderedQTag            = 0x22         // Tag for ordered queue 
  737. };
  738.  
  739. //——————————————————————————————————————————————————————————————————————
  740. // Defines for the Bus Inquiry PB fields.
  741. //——————————————————————————————————————————————————————————————————————
  742.  
  743. // scsiHBAInquiry field bits
  744.  
  745. #define    scsiBusMDP                0x80    // Supports Modify Data Pointer message
  746. #define    scsiBusWide32            0x40    // Supports 32 bit wide SCSI
  747. #define    scsiBusWide16            0x20    // Supports 16 bit wide SCSI
  748. #define    scsiBusSDTR                0x10    // Supports Sync Data Transfer Req message
  749. #define    scsiBusLinkedCDB        0x08    // Supports linked CDBs
  750. #define    scsiBusTagQ                0x02    // Supports tag queue message 
  751. #define    scsiBusSoftReset        0x01    // Supports soft reset
  752.  
  753.  
  754. // scsiDataTypes field bits 
  755. //    bits 0->15 Apple-defined, 16->30 3rd-party unique, 31 = reserved
  756.  
  757. #define scsiBusDataTIB            (1<<scsiDataTIB)        // TIB supplied (ptr in scsiDataPtr)
  758. #define scsiBusDataBuffer        (1<<scsiDataBuffer)    // single contiguous buffer supplied 
  759. #define scsiBusDataSG            (1<<scsiDataSG)        // scatter/gather list supplied 
  760.  
  761. #define scsiBusDataReserved        0x80000000    //  
  762.  
  763.  
  764. // scsiTargetModeFlags field bits
  765.  
  766. #define scsiBusTargetMdProcessor    0x80    // Target mode processor mode 
  767. #define scsiBusTargetMdPhase        0x40    // Target mode phase cog. mode
  768.  
  769.  
  770. // scsiScanFlags field bits
  771.  
  772. #define scsiBusScansDevices            0x80    // Bus scans for and maintains device list
  773. #define scsiBusScansOnInit            0x40    // Bus scans performed at power-up/reboot
  774. #define scsiBusLoadsROMDrivers        0x20    // may load ROM drivers to support targets
  775.  
  776.  
  777. // scsiFeatureFlags field bits
  778.  
  779. #define scsiBusInternalExternalMask        0x000000C0    // bus internal/external mask
  780. #define scsiBusInternalExternalUnknown    0x00000000    // not known whether bus is inside or outside
  781. #define scsiBusInternalExternal            0x000000C0    // bus goes inside and outside the box
  782. #define scsiBusInternal                    0x00000080    // bus goes inside the box
  783. #define scsiBusExternal                    0x00000040    // bus goes outside the box
  784.  
  785. #define scsiBusCacheCoherentDMA            0x00000020    // DMA is cache coherent
  786. #define scsiBusOldCallCapable            0x00000010    // SIM is old call capable
  787.  
  788. #define scsiBusDifferential                0x00000004    // Single Ended (0) or Differential (1)
  789. #define scsiBusFastSCSI                    0x00000002    // HBA supports fast SCSI
  790. #define scsiBusDMAavailable                0x00000001    // DMA is available
  791.  
  792.  
  793. // scsiWeirdStuff field bits
  794.  
  795. #define scsiOddDisconnectUnsafeRead1    0x0001    // 
  796. #define scsiOddDisconnectUnsafeWrite1    0x0002    // 
  797. #define    scsiBusErrorsUnsafe                0x0004    //
  798. #define    scsiRequiresHandshake            0x0008    //
  799. #define scsiTargetDrivenSDTRSafe        0x0010    // 
  800.  
  801.  
  802.  
  803. //———————————————————————————————————————————————————————————————————————————————————
  804. //  Defines for the scsiDriverFlags field (in SCSI_Driver_PB)
  805. //———————————————————————————————————————————————————————————————————————————————————
  806.  
  807. #define    scsiDeviceSensitive            0x0001    // Only driver should access this device
  808. #define    scsiDeviceNoOldCallAccess    0x0002    // no old call access to this device
  809.  
  810.  
  811.  
  812. //——————————————————————————————————————————————————————————————————————
  813. //  SIMinitInfo
  814. //——————————————————————————————————————————————————————————————————————
  815.  
  816. typedef struct {            // directions are for SCSIRegisterBus call ( -> parm, <- result)
  817.     unsigned char *        SIMstaticPtr;        // <- alloc. ptr to the SIM's static vars
  818.     long        staticSize;            // -> num bytes SIM needs for static vars
  819.     OSErr        (*SIMinit)();        // -> pointer to the SIM init routine
  820.     void        (*SIMaction)();        // -> pointer to the SIM action routine
  821.     long        (*SIM_ISR)();        // -> pointer to the SIM ISR routine
  822.     long        (*SIMInterruptPoll)();    // -> pointer to the SIM interrupt poll routine
  823.     void        (*NewOldCall)();    // -> pointer to the SIM NewOldCall routine
  824.     unsigned short        ioPBSize;            // -> size of SCSI_IO_PBs required for this SIM
  825.     Boolean        oldCallCapable;        // -> true if this SIM can handle old-API calls
  826.     unsigned char        simInfoUnused1;        // ->
  827.     long        simInternalUse;        // xx not affected or viewed by XPT
  828.     void        (*XPT_ISR)();        // <- ptr to the XPT ISR
  829.     void        (*EnteringSIM)();    // <- ptr to the EnteringSIM routine
  830.     void        (*ExitingSIM)();    // <- ptr to the ExitingSIM routine
  831.     void        (*MakeCallback)();    // <- pointer to the XPT layer’s MakeCallback routine
  832.     unsigned short        busID;                // <- bus number for the registered bus
  833.     unsigned short        simInfoUnused3;        // <- 
  834.     long        simInfoUnused4;        // <- 
  835. } SIMinitInfo; 
  836.  
  837.  
  838.  
  839. /********* Glue between SCSI calls and SCSITrap format ***********/
  840.  
  841. enum {
  842.     xptSCSIAction            = 0x0001,
  843.     xptSCSIRegisterBus        = 0x0002,
  844.     xptSCSIDeregisterBus    = 0x0003,
  845.     xptSCSIReregisterBus    = 0x0004,
  846.     xptSCSIKillXPT            = 0x0005    // kills Mini-XPT after transition 
  847. };
  848.  
  849. #ifdef __cplusplus
  850. extern "C" {
  851. #endif
  852.  
  853. #pragma parameter __D0    SCSIAction(__A0)            /* moveq #kSCSIx, D0;  _SCSIAtomic */
  854. OSErr                    SCSIAction(SCSI_PB *)                = {0x7001, _SCSIAtomic}; 
  855.  
  856. #pragma parameter __D0    SCSIRegisterBus(__A0)
  857. OSErr                    SCSIRegisterBus(SIMinitInfo *)        = {0x7002, _SCSIAtomic}; 
  858.  
  859. #pragma parameter __D0    SCSIDeregisterBus(__A0)
  860. OSErr                    SCSIDeregisterBus(SIMinitInfo *)    = {0x7003, _SCSIAtomic}; 
  861.  
  862. #pragma parameter __D0    SCSIReregisterBus(__A0)
  863. OSErr                    SCSIReregisterBus(SIMinitInfo *)    = {0x7004, _SCSIAtomic}; 
  864.  
  865. #pragma parameter __D0    SCSIKillXPT(__A0)
  866. OSErr                    SCSIKillXPT(SIMinitInfo *)            = {0x7005, _SCSIAtomic}; 
  867.  
  868. #ifdef __cplusplus
  869. }
  870. #endif
  871.  
  872. #endif __SCSI__
  873.